<form id="edit_menu" style="margin-top: 15px;" class="layui-form" action="{{session('guard')=='system'?route('system.menu.update',['id'=>$menu['id']]):route('admin.menu.update',['id'=>$menu['id']])}}"
      method="post">
    {{csrf_field()}}
    <div class="layui-form-item">
        <label class="layui-form-label">父栏目</label>
        <div class="layui-input-block">
            <div id="parent_id" style="width: 60%"></div>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="name" autocomplete="off" placeholder="请输入菜单名称" value="{{$menu['name']}}"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">守卫</label>
        <div class="layui-input-block">
            <select id="type" name="guard_name" disabled lay-verify="required">
                {!! Code::getOptionsByCode('GUARD','',$menu['guard_name']) !!}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">显示图标</label>
        <div class="layui-input-block">
            <input type="text" id="icon" name="icon" autocomplete="off" placeholder="显示图标" value="{{$menu['icon']}}"
                   class="layui-input">
        </div>
    </div>

    @if(session('guard')=='system')
        <div class="layui-form-item" id="link_group">
            <label class="layui-form-label" id="66666">选择路由方式</label>
            <div class="layui-input-block">
                <input type="radio" name="is_link" value="1" @if($menu['is_link']==1) checked="" @endif title="链接">
                <input type="radio" name="is_link" value="0" @if($menu['is_link']==0) checked="" @endif title="路由">
            </div>
        </div>

        <div class="layui-form-item" style="display:none;">
            <label class="layui-form-label">链接地址</label>
            <div class="layui-input-block">
                <input type="text" id="uri_link" name="uri_link" autocomplete="off" placeholder="链接地址"
                       class="layui-input" @if($menu['is_link']==1) value="{{$menu['uri']}}" @endif>
                <div class="layui-form-mid layui-word-aux">请以https://或http://开头</div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">路由</label>
            <div class="layui-input-block">
                <input
                    onblur="admin.send('{{session("guard")=='system'?route('system.menu.check'):route('admin.menu.check')}}','GET',{'data':{'name':this.value}},0)"
                    type="text" id="uri" name="uri" autocomplete="off" placeholder="跳转路由" class="layui-input"
                    @if($menu['is_link']==0) value="{{$menu['uri']}}" @endif>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">路由参数</label>
            <div class="layui-input-block">
                <textarea type="text" id="data" name="data" autocomplete="off" placeholder="路由参数" class="layui-textarea">{{$menu['data']}}</textarea>
                <div class="layui-text" style="color: red;font-size: 12px;width: 60%">输入路由参数，每一组一行，例：group|value(参数名称|参数值)</div>
            </div>
        </div>
    @else
        <div class="layui-form-item" style="display:none;">
            <label class="layui-form-label">链接地址</label>
            <div class="layui-input-block">
                <input type="text" id="uri_link" name="uri_link" autocomplete="off" placeholder="链接地址"
                       class="layui-input" value="{{$menu['uri']}}">
                <div class="layui-form-mid layui-word-aux">请以https://或http://开头</div>
                <input name="is_link" value="1" style="display: none;">
            </div>
        </div>
    @endif


</form>
<script type="text/javascript">
    $(function () {
        //判断是链接还是路由
        let is_link = {{$menu['is_link']}};
        link_show(is_link);


        $("#link_group").click(function () {
            let val = $("input[name='is_link']:checked").val();
            link_show(val);
        });
    })

    function link_show(is_link) {
        if (is_link == 1) {
            $("#uri_link").parent().parent().show();
            $("#uri").parent().parent().hide();
        }
        if (is_link == 0) {
            $("#uri_link").parent().parent().hide();
            $("#uri").parent().parent().show();
        }
    }

</script>

<script src="{{asset('layui/modules/xm-select.js')}}"></script>
<script src="{{asset('js/tree/select.js')}}"></script>
<script>
    var idx = -1;
    layui.use(['xmSelect'], function () {
        var xmSelect = layui.xmSelect;

        let params=selectTreeParams('#parent_id','parent_id','请选择',"{{$menu['parent_id']}}",JSON.parse('{!! $menus !!}'),function (data){
            $(".perPar").val(data.arr[0].id);
        });
        xmSelect.render(params)
    });
</script>
